package com.fusion.lottery.auth.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fusion.lottery.auth.service.RoleService;
import com.fusion.lottery.entity.auth.Authorization;
import com.fusion.lottery.entity.auth.Role;
import com.fusion.lottery.mapper.auth.RoleMapper;
import com.fusion.utils.json.Msg;
import com.fusion.utils.json.QueryResult;

@Service
public class RoleServiceImpl implements RoleService{
	
	@Autowired
	private RoleMapper roleMapper;
	
	public Msg list(Role role,long start,long pageSize) {
		List<Role> list = roleMapper.list(role,start,pageSize);
		QueryResult qs = new QueryResult(list,roleMapper.count(role));
		return new Msg(qs);
	}
	
	public Msg get(long id) {
		Role role = roleMapper.get(id);
		return new Msg(role);
	}
	
	public Msg add(Role role) {
		roleMapper.insert(role);
		return new Msg(role);
	}
	
	public Msg update(Role role) {
		roleMapper.update(role);
		return new Msg();
	}
	
	public Msg delete(long id) {
		roleMapper.delete(id);
		return new Msg();
	}

	@Override
	public Msg getPermission(long roleId) {
		// TODO Auto-generated method stub
		return new Msg(roleMapper.getPermission(roleId));
	}

	@Override
	public Msg getUser(long roleId) {
		// TODO Auto-generated method stub
		return new Msg(roleMapper.getUser(roleId));
	}

	@Override
	public Msg grantRole(Authorization authorization) {
		// TODO Auto-generated method stub
		roleMapper.grantRole(authorization);
		return new Msg();
	}

	@Override
	public Msg recoverRole(Authorization authorization) {
		// TODO Auto-generated method stub
		roleMapper.recoverRole(authorization);
		return new Msg();
	}

	@Override
	public Msg grantPermission(long roleId, String sourceIds) {
		// TODO Auto-generated method stub
		roleMapper.recoverPermission(roleId);
//		roleMapper.grantPermission(roleId, java.util.Arrays.asList(sourceIds.split(",")));
		roleMapper.grantPermission(roleId, sourceIds);
		return new Msg();
	}

}
